package com.readbook.util;


import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.http.util.EntityUtils;


import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;


import java.io.IOException;


public class HttpClientUtil {


    public static String sendGet(String url) {

        String html = "";
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(url);
        HttpMethodParams params = new HttpMethodParams();
        //params.setParameter("UserID", "99999005");
        //params.setParameter("Action", "Login");
        get.setParams(params);
        try {
            int statusCode = client.executeMethod(get);
            if (statusCode == 200) {
                html = get.getResponseBodyAsString();
            }
            get.releaseConnection();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return html;

    }


    public static String sendGet1(String url) {

        String html = "";
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(url);
        HttpMethodParams params = new HttpMethodParams();
        params.setParameter("Content-Type", "appplication/json");
        params.setParameter("Platform", "third");
        params.setParameter("Authorization", "fafde5794bd473c89f81e6f1fb787071-1-27");
        get.setParams(params);
        try {
            int statusCode = client.executeMethod(get);
            if (statusCode == 200) {
                html = get.getResponseBodyAsString();
            }
            get.releaseConnection();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return html;

    }

}
